package edu.whut.movieMangement;

import edu.whut.movieMangement.Movie;

import java.util.Scanner;

public class MovieService {
    private Movie[] movies;
    private Scanner sc = new Scanner(System.in);
    public MovieService(Movie[] movies) {
        this.movies = movies;
    }

    /**
     * 启动电影信息管理系统
     */
    public void start() {
        lo:
        while (true) {
        System.out.println("------------------------");
        System.out.println("请输入你的选择：");
        System.out.println("1.查询全部电影信息");
        System.out.println("2.根据id查询电影");
        System.out.println("3.退出");

            int choice = sc.nextInt();
            switch (choice) {
                case 1:
                    findMovies();
                    break;
                case 2:
                    findMovieById();
                    break;
                case 3:
                    System.out.println("再见！");
                    break lo;
                default:
                    System.out.println("输入错误，请检查！");
                    break;
            }
        }
    }

    /**
     * 根据编号查电影信息
     */
    private void findMovieById() {
        System.out.println("请输入电影编号：");
        int id = sc.nextInt();
        for (int i = 0; i < movies.length; i++) {
            Movie movie = movies[i];
            if(movie.getId()==id){
                System.out.println(movie.getTitle()+"---"+movie.getScore()+"-----"+movie.getDirector()+"---"+movie.getStarring());
                //结束方法
                return;
            }
        }
        System.out.println("找不到！");
    }

    /**
     * 展示全部电影信息
     */
    private void findMovies() {
        //取出每一个电影对象
        for (int i = 0; i < movies.length; i++) {
            Movie movie = movies[i];
            //根据电影对象，使用get方法，获取电影信息
            System.out.println(movie.getTitle()+"---"+movie.getScore());
        }
    }

}
